package com.cw.reduce.filter;

import java.util.Vector;

//import cp.util.CountTimes;

public class CountFilter implements IFilter {
	private static String[] countType = { "=0", "=1", "=2", "=3", "=4", "<2",
			"<3", ">0", ">1", ">2", ">3", ">4" }; // jo ou

	private static int[] valueBin = new int[6];
	private static String valueString[] = { "100001100000", "010001110000",
			"001000111000", "000100011000", "000010011110", "000000011111" };
	static {
		for (int i = 0; i < valueString.length; i++) {
			int sum = 0;
			for (int j = 0; j < valueString[i].length(); j++) {
				if (valueString[i].charAt(j) == '1') {
					sum = (sum << 1) + 1;
				}
				if (valueString[i].charAt(j) == '0') {
					sum = sum << 1;
				}
			}
			valueBin[i] = sum;
		}
	}

//	private CountTimes counttime;
//
//	public CountFilter(CountTimes tar) {
//		this.counttime = tar;
//	}

	private boolean judgeDigit(int value, String select) {
		int sel = 1;
		for (int i = 0; i < countType.length; i++) {
			if (countType[i].equals(select)) {
				sel = sel << (11 - i);
				break;
			}
		}
		if ((valueBin[value] & sel) == sel) {
			return true;
		}
		return false;
	}

	/**
	 * startFilter
	 * 
	 * @param condition
	 *            Vector
	 * @param target
	 *            Vector
	 * @return Vector
	 * @todo Implement this cp.gui.reduce.filter.IFilter method
	 */
	public Vector startFilter(Vector condition, Vector<Integer> target) {
		Vector<Integer> result = new Vector<Integer>();
		String condi = (String) condition.elementAt(0);

//		for (int i = 0; i < target.size(); i++) {
//			int value = target.elementAt(i);
//			int count = counttime.getTimes(value);
//			if (count >= 5) {
//				count = 5;
//			}
//
//			if (judgeDigit(count, condi)) {
//				result.add(value);
//			}
//		}

		return result;
	}

}
